home *** CD-ROM | disk | FTP | other *** search
Wrap
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <string.h> #include <conio.h> #include "allegro.h" #include "card.h" BITMAP *buffer, *tempa, *treepic, *transparence; COMPILED_SPRITE *rot[46][42]; int sintbl[42] = { 0, -5, -11, -17, -22, -27, -31, -34, -37, -39, -39, -39, -39, -37, -34, -31, -27, -22, -17, -11, -5, 0, 5, 11, 17, 22, 27, 31, 34, 37, 39, 39, 39, 39, 37, 34, 31, 27, 22, 17, 11, 5, }; int costbl3[210] = { 112, 111, 111, 111, 111, 111, 111, 110, 110, 110, 109, 109, 108, 107, 107, 106, 105, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 94, 93, 92, 91, 89, 88, 87, 85, 84, 82, 81, 79, 78, 76, 75, 74, 72, 71, 69, 67, 65, 64, 63, 61, 59, 57, 56, 54, 52, 50, 49, 48, 46, 44, 42, 41, 39, 38, 37, 35, 34, 32, 31, 29, 28, 26, 25, 24, 22, 21, 20, 19, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 24, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 39, 41, 42, 44, 46, 48, 49, 50, 52, 54, 56, 57, 59, 61, 63, 64, 65, 67, 69, 71, 72, 74, 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 89, 91, 92, 93, 94, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 105, 106, 107, 107, 108, 109, 109, 110, 110, 110, 111, 111, 111, 111, 111, 111 }; char costbl2[280] = { 63, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 59, 59, 59, 59, 59, 59, 59, 58, 58, 58, 58, 58, 58, 58, 58, 57, 57, 57, 57, 57, 57, 57, 56, 56, 56, 56, 56, 56, 55, 55, 55, 55, 55, 55, 54, 54, 54, 54, 54, 54, 53, 53, 53, 53, 53, 53, 52, 52, 52, 52, 51, 51, 51, 51, 51, 51, 50, 50, 50, 50, 50, 49, 49, 49, 49, 48, 48, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46, 46, 46, 45, 45, 45, 45, 44, 44, 44, 44, 44, 43, 43, 43, 43, 42, 42, 42, 42, 42, 41, 41, 41, 40, 40, 40, 40, 39, 39, 39, 39, 39, 38, 38, 38, 38, 37, 37, 37, 36, 36, 36, 36, 35, 35, 35, 35, 35, 34, 34, 34, 33, 33, 33, 33, 32, 32, 32, 32, 32, 31, 31, 31, 30, 30, 30, 30, 29, 29, 29, 28, 28, 28, 28, 28, 27, 27, 27, 27, 26, 26, 26, 25, 25, 25, 25, 25, 24, 24, 24, 24, 23, 23, 23, 23, 23, 22, 22, 22, 21, 21, 21, 21, 20, 20, 20, 20, 19, 19, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 11, 11, 11 }; char costbl[536] = { 63, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 61, 61, 61, 61, 60, 60, 60, 60, 59, 59, 58, 58, 58, 57, 57, 56, 56, 55, 55, 54, 54, 53, 53, 52, 51, 51, 50, 50, 49, 48, 48, 47, 46, 46, 45, 44, 44, 43, 42, 42, 41, 40, 39, 39, 38, 37, 36, 36, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28, 27, 27, 26, 25, 24, 24, 23, 22, 21, 21, 20, 19, 19, 18, 17, 17, 16, 15, 15, 14, 13, 13, 12, 12, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 27, 27, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 39, 39, 40, 41, 42, 42, 43, 44, 44, 45, 46, 46, 47, 48, 48, 49, 50, 50, 51, 51, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 57, 58, 58, 59, 59, 59, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 63, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 61, 61, 61, 61, 60, 60, 60, 60, 59, 59, 58, 58, 58, 57, 57, 56, 56, 55, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 49, 49, 48, 47, 47, 46, 45, 45, 44, 43, 43, 42, 41, 40, 39, 39, 38, 37, 36, 36, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28, 27, 27, 26, 25, 24, 24, 23, 22, 21, 21, 20, 19, 19, 18, 17, 17, 16, 15, 15, 14, 13, 13, 12, 12, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, 23, 24, 25, 25, 26, 27, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 39, 39, 40, 41, 42, 42, 43, 44, 44, 45, 46, 46, 47, 48, 48, 49, 50, 50, 51, 51, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 57, 58, 58, 59, 59, 59, 60, 60, 60, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 63, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 61, 61, 61, 61, 60, 60, 60, 60, 59, 59, 58, 58, 58, 57, 57, 56, 56 }; volatile int game_time = 1; long frame_count = 8; double speed = 2; unsigned char tree=0,end=0,song=1,col[100],*colptr,message[1024],temptbl[281]; double tmov1=0,tmov2=0,tmov3=0,tmov4=0; signed char s_pos=5,s_row=0,s_col=0,p_col=0,m_col=0,s_rows; signed char songpos,picpos,bgpos,textpos,dots=0,font_change=0; char song_name[16],pic_name[16];int offsets[14],xpos[100],*xposptr; MIDI *the_song; BITMAP *intro_pic;DATAFILE *datafile; RGB pal[242][256],picpal[256]; void game_timer() { game_time++; } insert_chara(char *strp, int pos, char ins) { int w; for(w=strlen(strp);w>pos;w--) strp[w]=strp[w-1]; strp[pos]=ins; } delete_chara(char *strp, int pos) { int w; for(w=pos;w<strlen(strp);w++) strp[w]=strp[w+1]; strp[strlen(strp)]=0; } void main(int argc, char *argv[]) { int x, z=0, zo=0, zp=0, zq=0; double zd=0; unsigned char *c, *c2, y; char buf[5]; buffer = create_bitmap(325,135); clear(buffer); for(x=1;x<argc;x++) { if(strstr(argv[x], "-f") || strstr(argv[x], "-F") || strstr(argv[x], "/f") || strstr(argv[x], "/F")) font_change = 1; if(strcmp(argv[x], "-?") || strstr(argv[x], "/?") || strstr(argv[x], "-h") || strstr(argv[x], "-H") || strstr(argv[x], "/h") || strstr(argv[x], "/H") || strstr(argv[x], "-s") || strstr(argv[x], "-S") || strstr(argv[x], "/s") || strstr(argv[x], "/S")) setup_mode(); } c2=message; init(); while(!key[KEY_ESC]) { if(end) textpos = 0; if(!textpos) drawplasma(); else clear(buffer); if(!end) { if(z-zo>=18) { *c2++; zo=z; if(key[KEY_F]) { sprintf(buf, "%d=%d", 4*frame_count/game_time, (int)(40*frame_count/game_time)%10); draw_word(1,1,buf,1);draw_word(1,1,buf,2); } } c = c2; for(x=(20-(z-zo));x<300;x+=18) { if(*c < 46) draw_compiled_sprite(buffer, rot[*c][((x*3+z)%840)/20], x, costbl3[((x*3+z)%840)/4]); *c++; } if(*c==128) {tree = 1; end = 1;} } if(textpos) drawplasma(); if(z-zq>=2) { zq=z; xposptr = xpos; colptr = col; for(x=0;x<100;x++) { if(*xposptr<320 && tempa->line[x*2+1][*xposptr]<14) _putpixel(screen,*xposptr,x*2+1,0); *xposptr -= ((*colptr/2)-2); if(*xposptr < 0) { *xposptr = 320+random()%160; *colptr = random()%6+7; } if(*xposptr<320 && tempa->line[x*2+1][*xposptr]<14) _putpixel(screen,*xposptr,x*2+1,*colptr); xposptr++;colptr++; } if(key[KEY_T]) {tree = 1;screen->vtable->blit_from_memory(datafile[TREE].dat, treepic, 0, 0, 0, 0, 280, 125);} else if(key[KEY_C]) {tree = 1;screen->vtable->blit_from_memory(datafile[CROSS].dat, treepic, 0, 0, 0, 0, 280, 125);} else if(key[KEY_N]) tree = 0; } if(z-zp>=4) {zp=z; _vga_set_pallete_range(pal[z/4%242], 14, 255, 1);} screen->vtable->blit_from_memory(buffer, screen, 20, 5, 20, 60, 280, 125); zd+=speed;z = (int)zd;frame_count++; speed = ((double)10*game_time)/(double)frame_count; if(frame_count>=10000) {frame_count /= 4; game_time /= 4;} } set_pallete_range(pal[z/4%242], 0, 255, 1); fade_out(2); clear(screen); draw_word(10, 90,"merry christmas",0); fade_in(datafile[PALLETE_001].dat, 2); rest(2000); fade_out(2); allegro_exit(); printf("---------------------------------------------------\n"); printf("This programme was brought to you by Michael Bevin.\n"); printf("You may use it as an 'electronic christmas card' by\n"); printf("editing the message in setup (card -s) provided you\n"); printf("do not edit the original program files. Feel free 2\n"); printf("e-mail me at michael.bevin@stonebow.otago.ac.nz if \n"); printf("u like it or want to know how I made it etc. \n"); printf("---------------------------------------------------\n"); clear_keybuf(); exit(0); } drawplasma() { unsigned char x, *p1, *p3, *p6, *p7, *p8, mov; register unsigned char tmov, *p4, *p2; unsigned long address; tmov1+=((double)(random()%2-4)*speed/2.5); tmov2-=((double)(random()%3)*speed/2.5); tmov3+=((double)(random()%2+4)*speed/2.5); tmov4-=((double)(random()%3)*speed/2.5); p2 = temptbl; if(tree) p3 = &treepic->line[0][0]; p4 = &buffer->line[5][20] - 1; p6 = costbl2; mov=(int)tmov2; p7 = &costbl[mov]; mov=(int)tmov1; p8 = &costbl[mov]; while(*p2) *p2++=*p6++ + *p7++ + *p8++; p6 = costbl2; p2 = temptbl; mov=(int)tmov3; p7 = &costbl[mov]; mov=(int)tmov4; p8 = &costbl[mov]; if(!textpos) address = bmp_write_line(buffer, 5)+20; for(x=0;x<125;x++) { tmov=*p6++ + *p7++ + *p8++; if(!textpos) { _movedatal(_my_ds(),(unsigned)p2,buffer->seg,address,71); address+=325; } else p2 = temptbl; if(tree && textpos) {while(*p2){*(++p4)+=*p2++ + *p3++ +tmov;if(*p4<tmov) *p4+=14;} p4+=45;} else if(textpos) {while(*p2){*(++p4)+=*p2++ +tmov;if(*p4<tmov) *p4+=14;} p4+=45;} else if(tree) {while(*(++p4)){*p4+=*p3++ +tmov;if(*p4<tmov) *p4+=14;} p4+=44;} else {while(*(++p4)){*p4+=tmov;if(*p4<tmov) *p4+=14;} p4+=44;} } } draw_word(int xx, int yy, char *cc, int boris) { BITMAP *letter; int v, w, y, z; z = strlen(cc); letter = create_bitmap(z*20,16); clear(letter); for(w=0; w<z;w++) { v = *cc++ - 97; if(v >= 0 && v < 26) y = 1; else {v += 49;y=19;} if(v >= 0 && v < 26) blit(datafile[FONT].dat, letter, v*17+1, y, w*20, 0, 16, 16); } for(v=0;v<16;v++) { for(w=0;w<(z*20);w++) if(boris) letter->line[v][w] = getpixel(letter, w, v) ? (xx+w+v)%242+14 : 0; else letter->line[v][w] = getpixel(letter, w, v); } screen->vtable->blit_from_memory(letter, screen, 0, 0, xx, yy, z*20, 16); if(boris==2) screen->vtable->blit_from_memory(letter, tempa, 0, 0, xx, yy, z*20, 16); destroy_bitmap(letter); } init() { int x, z; RGB rgbt[498]; unsigned char *pa, *pb, mtemp[1024]; x = time(0); srandom(x); allegro_init(); install_keyboard(); install_timer(); open_file(); if(songpos != 2) if (install_sound(DIGI_NONE, MIDI_AUTODETECT, NULL) != 0) songpos = 2; datafile = load_datafile("card.dat"); if(!datafile){allegro_exit();printf("Error loading card.dat\n\n");exit(1);} strcpy(mtemp,message); pa=message; pb = mtemp; for(x=0;x<19;x++) *pa++=255; while(*pb) { if(*pb > 47 && *pb < 65) *pa = *pb-22; else if(*pb > 96 && *pb < 123) *pa = *pb-97; else if(*pb > 64 && *pb < 91) *pa = *pb-65; else *pa = 255; if (*pb==33) *pa=38; if (*pb==46) *pa=39; if (*pb==44) *pa=40; if (*pb>38 && *pb < 42) *pa=*pb+2; if (*pb==45) *pa=44; if (*pb==63) *pa=45; *pa++; *pb++; } for(x=0;x<24;x++) *pa++=255; *pa=128; if(songpos != 2) { if(songpos == 0) play_midi(datafile[SONG1].dat, TRUE); else if(songpos == 1) play_midi(datafile[SONG2].dat, TRUE); else { the_song = load_midi(song_name); if(play_midi(the_song, TRUE) || !the_song) { allegro_exit(); printf("Error loading %s\n\n",song_name); exit(1); } } } set_gfx_mode(GFX_MODEX, 360, 360, 0, 0); set_pallete_range(datafile[PALLETE_001].dat, 0, 255, 1); get_pallete(rgbt); set_pallete_range(black_pallete, 1, 255, 1); x=random()%2; if(picpos == 2) { if(!x) screen->vtable->blit_from_memory(datafile[BOY].dat, screen, 0, 0, 40, 40, 280, 280); else screen->vtable->blit_from_memory(datafile[ANGEL].dat, screen, 0, 0, 40, 40, 280, 280); } else { if (!picpos) screen->vtable->blit_from_memory(datafile[BOY].dat, screen, 0, 0, 40, 40, 280, 280); else if (picpos == 1) screen->vtable->blit_from_memory(datafile[ANGEL].dat, screen, 0, 0, 40, 40, 280, 280); else { intro_pic = load_pcx(pic_name,picpal); if (intro_pic->w<360) x=intro_pic->w; else x=360; if (intro_pic->h<360) z=intro_pic->h; else z=360; screen->vtable->blit_from_memory(intro_pic, screen, 0, 0, (360-x)/2, (360-z)/2, x, z); } } if(picpos == 3) fade_in(picpal, 2); else fade_in(datafile[PALLETE_002].dat, 2); destroy_bitmap(datafile[BOY].dat); destroy_bitmap(datafile[ANGEL].dat); for(z=0;z<242;z++) rgbt[z+256]=rgbt[z+14]; transparence = create_bitmap(443,37); tempa = create_bitmap(16, 16); treepic = create_bitmap(20, 20); if(textpos) blit(datafile[FONTT].dat, transparence, 0, 0, 0, 0, 443, 37); else blit(datafile[FONT].dat, transparence, 0, 0, 0, 0, 443, 37); for(x=0;x<280;x++) { temptbl[x] = 1; if(x<242) { memcpy(&pal[x][0],&rgbt[0],56); memcpy(&pal[x][14],&rgbt[x+14],968); } if(x<100) {xpos[x] = random()%320;col[x] = random()%6+7;} if(x<46) { if(x<26) blit(transparence, tempa, x*17+1, 1, 0, 0, 16, 16); else blit(transparence, tempa, (x-26)*17+1, 19, 0, 0, 16, 16); for(z=0;z<42;z++) { clear(treepic); rotate_sprite(treepic,tempa,2,2,itofix(sintbl[z])); rot[x][z]=get_compiled_sprite(treepic, 0); } } } destroy_bitmap(transparence);destroy_bitmap(tempa); destroy_bitmap(treepic);destroy_bitmap(datafile[FONTT].dat);temptbl[280]=0; if(!textpos) set_clip(buffer,0,0,0,0);else set_clip(buffer,20,5,300,130); fade_out(2); set_gfx_mode(GFX_VGA, 320, 200, 0, 0); set_pallete_range(black_pallete, 1, 255, 1); treepic = create_bitmap(280,125);tempa=create_bitmap(320,200); if(bgpos) { tree = 1; if(bgpos == 1) screen->vtable->blit_from_memory(datafile[TREE].dat, treepic, 0, 0, 0, 0, 280, 125); else screen->vtable->blit_from_memory(datafile[CROSS].dat, treepic, 0, 0, 0, 0, 280, 125); } else screen->vtable->blit_from_memory(datafile[TREE].dat, treepic, 0, 0, 0, 0, 280, 125); drawplasma(); draw_word(10,20, "merry christmas",1); screen->vtable->blit_from_memory(buffer, screen, 20, 5, 20, 60, 280, 125); screen->vtable->blit_from_memory(screen, tempa, 0, 0, 0, 0, 320, 200); fade_in(datafile[PALLETE_001].dat, 2); install_int(game_timer, 250); } setup_mode() { struct text_info i; int x,y;unsigned int keyp; char buff[5000];FILE *fp; open_file(); gettextinfo(&i); gettext(1,1,80,25,buff); allegro_init(); install_keyboard(); textmode(C80); system("funfont.com"); _setcursortype(_NOCURSOR); textattr (RED*16 | 15); gotoxy(1,1); cprintf(" Christmas Card v1.5 Setup - This program is freeware created by Michael Bevin "); textattr (BLUE*16 | 15); gotoxy(0,23);cprintf(" Press <F10> to quit and save, <Esc> to quit without saving "); textattr (LIGHTGRAY*16 | LIGHTBLUE); fill_text_screen(); gotoxy(5,5); cprintf("Boy & santa claus"); gotoxy(5,6); cprintf("Angel with wings"); gotoxy(5,7); cprintf("Randomly either"); gotoxy(25,5);cprintf("Danish carols"); gotoxy(25,6);cprintf("Away in a manger"); gotoxy(25,7);cprintf("Music disabled"); gotoxy(45,5);cprintf("Normal"); gotoxy(45,6);cprintf("Transparent"); gotoxy(58,5);cprintf("None at start"); gotoxy(58,6);cprintf("Christmas tree"); gotoxy(58,7);cprintf("Cross"); textattr (LIGHTGRAY*16 | LIGHTMAGENTA); draw_text_line(4, 10, 72); textattr (LIGHTGRAY*16 | LIGHTRED); gotoxy(4,picpos+5);cprintf("%c",4); gotoxy(24,songpos+5);cprintf("%c",4); gotoxy(44,textpos+5);cprintf("%c",4); gotoxy(57,bgpos+5);cprintf("%c",4); textattr (LIGHTGRAY*16 | MAGENTA); draw_text_line(4, 23, 72); textattr (LIGHTGRAY*16 | 14); gotoxy(5,3); cprintf("Intro Picture"); gotoxy(25,3); cprintf("Song (.MID) "); gotoxy(45,3); cprintf("Text Style"); gotoxy(58,3); cprintf("Plasma Background"); show_song_name(); show_pic_name(); show_message(); dots=1; gotoxy(5,11); while(!key[KEY_ESC] && !key[KEY_F10]) { if(keypressed() && !key[KEY_ESC]) { keyp=readkey(); if(keyp >> 8 == KEY_UP) { textattr (LIGHTGRAY*16 | LIGHTRED); switch(s_pos) { case 1: gotoxy(4,picpos+5);cprintf(" "); picpos--;if(picpos < 0) picpos = 3; gotoxy(4,picpos+5);cprintf("%c",4); break; case 2: gotoxy(24,songpos+5);cprintf(" "); songpos--;if(songpos < 0) songpos = 3; gotoxy(24,songpos+5);cprintf("%c",4); break; case 3: gotoxy(44,textpos+5);cprintf(" "); textpos--;if(textpos < 0) textpos = 1; gotoxy(44,textpos+5);cprintf("%c",4); break; case 4: gotoxy(57,bgpos+5);cprintf(" "); bgpos--;if(bgpos < 0) bgpos = 2; gotoxy(57,bgpos+5);cprintf("%c",4); break; default: s_row--; if(s_row<0) s_row=0; if(s_col>=(offsets[s_row+1]-offsets[s_row])) s_col = offsets[s_row+1]-offsets[s_row]-1; } show_pos(); } if(keyp >> 8 == KEY_DOWN) { textattr (LIGHTGRAY*16 | LIGHTRED); switch(s_pos) { case 1: gotoxy(4,picpos+5);cprintf(" "); picpos++;if(picpos > 3) picpos = 0; gotoxy(4,picpos+5);cprintf("%c",4); break; case 2: gotoxy(24,songpos+5);cprintf(" "); songpos++;if(songpos > 3) songpos = 0; gotoxy(24,songpos+5);cprintf("%c",4); break; case 3: gotoxy(44,textpos+5);cprintf(" "); textpos++;if(textpos > 1) textpos = 0; gotoxy(44,textpos+5);cprintf("%c",4); break; case 4: gotoxy(57,bgpos+5);cprintf(" "); bgpos++;if(bgpos > 2) bgpos = 0; gotoxy(57,bgpos+5);cprintf("%c",4); break; default: s_row++; if(s_row>s_rows) s_row=s_rows; if(s_row > 11) s_row = 11; if(s_col>=(offsets[s_row+1]-offsets[s_row])) s_col = offsets[s_row+1]-offsets[s_row]-1; } show_pos(); } if(keyp >> 8 == KEY_LEFT) { if(s_pos == 5) { s_col--; if(s_col<0 && s_row>0) { s_row--; s_col = offsets[s_row+1]-offsets[s_row]-1; } if(s_col<0) s_col = 0; } else if(s_pos == 1 && picpos == 3) { p_col--; if(p_col<0) p_col = 0; } else if(s_pos == 2 && songpos == 3) { m_col--; if(m_col<0) m_col = 0; } else { s_pos--;if(s_pos<0) s_pos=5; } show_pos(); } if(keyp >> 8 == KEY_END) { if(s_pos == 5) s_col=offsets[s_row+1]-offsets[s_row]-1; else if(s_pos == 1 && picpos == 3) p_col=strlen(pic_name); else if(s_pos == 2 && songpos == 3) m_col=strlen(song_name); show_pos(); } if(keyp >> 8 == KEY_HOME) { if(s_pos == 5) s_col=0; else if(s_pos == 1 && picpos == 3) p_col=0; else if(s_pos == 2 && songpos == 3) m_col=0; show_pos(); } if(keyp >> 8 == KEY_DEL) { _setcursortype(_NOCURSOR); if(s_pos == 5) { x = offsets[s_row]+s_col; delete_chara(message, offsets[s_row]+s_col); show_message(); if(s_col > offsets[s_row+1]-offsets[s_row]-1 && s_row<11) { s_row++; s_col = x - offsets[s_row]; } else if(s_col+offsets[s_row] > x && s_row) { s_row--; s_col = x - offsets[s_row]; } } else if(s_pos==1 && picpos == 3) { delete_chara(pic_name, p_col); show_pic_name(); } else if(s_pos==2 && songpos == 3) { _setcursortype(_NOCURSOR); delete_chara(song_name, m_col); show_song_name(); } show_pos(); _setcursortype(_NORMALCURSOR); } if(keyp >> 8 == KEY_BACKSPACE) { if(s_pos == 5) { s_col--; if(s_col<0 && !s_row) s_col = 0; else { x = offsets[s_row]+s_col; delete_chara(message, offsets[s_row]+s_col); show_message(); if(x != offsets[s_row]+s_col || s_col < 0) { if(x >= offsets[s_row]) s_col = x - offsets[s_row]; else { s_row--; s_col = x - offsets[s_row]; } } show_pos(); } } else if(s_pos == 1 && picpos == 3) { p_col--; if(p_col<0) p_col=0; else { delete_chara(pic_name, p_col); show_pic_name(); show_pos(); } } else if(s_pos == 2 && songpos == 3) { m_col--; if(m_col<0) m_col=0; else { delete_chara(song_name, m_col); show_song_name(); show_pos(); } } } if((keyp & 0xff) == 25) { for(x=offsets[s_row];x<920;x++) message[x]=message[x+offsets[s_row+1]-offsets[s_row]]; if(s_row >= s_rows) { if(s_row) { s_row--; s_col=offsets[s_row+1]-offsets[s_row]-1; message[s_col+offsets[s_row]] = 0; } else { s_col=0; message[0]=0; } } show_message(); show_pos(); } else if(((keyp & 0xff) > 19) && ((keyp & 0xff) < 124) && s_pos == 5 && (s_row<11 || s_col<69)) { x = offsets[s_row]+s_col; insert_chara(message, offsets[s_row]+s_col, keyp & 0xff); show_message(); s_col++; if(s_col>=(offsets[s_row+1]-offsets[s_row]) && s_row<s_rows && s_row<11) { s_row++; s_col = x+1-offsets[s_row]; } else if(x+1 < s_col+offsets[s_row]) s_col = 0; if(s_col>=(offsets[s_row+1]-offsets[s_row])) s_col = offsets[s_row+1]-offsets[s_row]-1; show_pos(); } if(((keyp & 0xff) > 19) && ((keyp & 0xff) < 124) && s_pos == 1 && picpos == 3) { _setcursortype(_NOCURSOR); insert_chara(pic_name, p_col, keyp & 0xff); if(p_col<15) p_col++; show_pic_name(); show_pos(); _setcursortype(_NORMALCURSOR); } if(((keyp & 0xff) > 19) && ((keyp & 0xff) < 124) && s_pos == 2 && songpos == 3) { _setcursortype(_NOCURSOR); insert_chara(song_name, m_col, keyp & 0xff); if(m_col<15) m_col++; show_song_name(); show_pos(); _setcursortype(_NORMALCURSOR); } if(keyp >> 8 == KEY_RIGHT) { if(s_pos == 5) { s_col++; if(s_col>=(offsets[s_row+1]-offsets[s_row]) && s_row<s_rows && s_row<11) { s_row++; s_col = 0; } if(s_col>=(offsets[s_row+1]-offsets[s_row])) s_col = offsets[s_row+1]-offsets[s_row]-1; } else if(s_pos == 1 && picpos == 3) { p_col++; if(p_col>strlen(pic_name)) p_col = strlen(pic_name); } else if(s_pos == 2 && songpos == 3) { m_col++; if(m_col>strlen(song_name)) m_col = strlen(song_name); } else { s_pos++;if(s_pos>5) s_pos=0; } show_pos(); } if(keyp >> 8 == KEY_TAB) { if(key[KEY_LSHIFT] || key[KEY_RSHIFT]) { s_pos--; if(!s_pos) s_pos = 5; } else { s_pos++; if(s_pos > 5) s_pos = 1; } show_pos(); } } } if(key[KEY_F10]) { if((fp = fopen("card.cfg","wb"))) { fwrite(message,1024,1,fp); fwrite(song_name,15,1,fp); fwrite(pic_name,15,1,fp); putc(songpos,fp); putc(picpos,fp); putc(bgpos,fp); putc(textpos,fp); fclose(fp); } } allegro_exit(); if(!font_change) textmode(C80); puttext(1,1,80,25,buff); gotoxy(i.curx,i.cury); textattr(i.attribute); exit(1); } show_pos() { switch(s_pos) { case 1: if(picpos < 3) gotoxy(4,picpos+5); else gotoxy(6+p_col,8); break; case 2: if(songpos < 3) gotoxy(24,songpos+5); else gotoxy(26+m_col,8); break; case 3: gotoxy(44,textpos+5); break; case 4: gotoxy(57,bgpos+5); break; default: gotoxy(s_col+5,s_row+11); } } show_message() { int x,y,end_mes=0, not_full=0; unsigned char temp_mes[71],*pm; offsets[0]=0; _setcursortype(_NOCURSOR); x=s_row-1; if(x<0) x=0; for(y=x;y<13;y++) { pm=message+offsets[y]; strncpy(temp_mes,pm,70); textattr (0 | LIGHTGRAY); x=70; while(x) { x--; if(temp_mes[x] == 32) not_full = 1; if(!end_mes && temp_mes[x] == 32) {offsets[y+1] = offsets[y]+x+1; x=0;} if(!end_mes && temp_mes[x] == 0) end_mes=1; if(end_mes && temp_mes[x]>0) {offsets[y+1] = offsets[y]+x+2;x=0;} if(x) temp_mes[x]=0; } if(!not_full && !end_mes) { offsets[y+1] = offsets[y]+69; strncpy(temp_mes,pm,70); } if(message[offsets[y]]==0) temp_mes[0]=0; if(offsets[y+1]<=offsets[y]) offsets[y+1] = offsets[y]; temp_mes[70]=0; if(y<12) { gotoxy(5,y+11); cprintf("%s",temp_mes); } textattr (0 | DARKGRAY); not_full = strlen(temp_mes); for(x=not_full;x<70;x++) cprintf("·"); if(end_mes) { s_rows=y; y++; if(y<12) { gotoxy(5,y+11); cprintf("······································································"); } if(!dots) { while(y<11) { gotoxy(5,++y+11); cprintf("······································································"); } } _setcursortype(_NORMALCURSOR); return(1); } } s_rows=y; _setcursortype(_NORMALCURSOR); } draw_text_line(int x, int y, int length) { int z; gotoxy(x,y); cprintf("■"); gotoxy(x+1,y); for (z=x+1;z<x+length-1;z++) cprintf("─"); gotoxy(x+length-1,y); cprintf("■"); } fill_text_screen() { int x,y; for(y=2;y<24;y++) { gotoxy(1,y); cprintf(" "); } } open_file() { FILE *fp; if((fp = fopen("card.cfg","rb"))) { fread(message,1024,1,fp);fread(song_name,15,1,fp);fread(pic_name,15,1,fp); songpos = getc(fp);picpos = getc(fp);bgpos = getc(fp);textpos = getc(fp); fclose(fp); } else { strcpy(message,"Merry christmas and a happy new year to all u computer users out there. This program is freeware and u may give it 2 your friends as an 'electronic christmas card' by editing this message (type card -s at command prompt)... The intro screen is a modex resolution at 360 by 360 so most pictures will b a bit squewed, but u can use pictures of any size and it should work ::: thanx to dj delorie for making djgpp, shawn hargreaves for the allegro game programming library, and christopher norton whose christmas carol music i stole ::: please write to me at michael.bevin at stonebow.otago.ac.nz if u like this or otherwise... and take some time out to remember what christmas is all about!! :"); strcpy(song_name,"<songname.mid>"); strcpy(pic_name,"<picname.pcx>"); } } show_pic_name() { pic_name[15]=0; textattr (0 | DARKGRAY); gotoxy(5,8); cprintf(">···············<"); textattr (0 | LIGHTGRAY); gotoxy(6,8); cprintf("%s",pic_name); } show_song_name() { song_name[15]=0; textattr (0 | DARKGRAY); gotoxy(25,8); cprintf(">···············<"); textattr (0 | LIGHTGRAY); gotoxy(26,8); cprintf("%s",song_name); }